package cn.jiahua.hospital.service.impl;


import cn.jiahua.hospital.dto.PageDepartmentDto;

import cn.jiahua.hospital.dto.TdepartmentsDto;

import cn.jiahua.hospital.mapper.TdepartmentsMapper;
import cn.jiahua.hospital.pojo.Tdepartments;
import cn.jiahua.hospital.service.TdepartmentsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

import javax.annotation.Resource;

@Service
public class TdepartmentsServiceImpl implements TdepartmentsService {

    @Resource
    private TdepartmentsMapper tdepartmentsMapper;

    @Override
    public TdepartmentsDto getTdepartmentsById(Integer id) {
        return tdepartmentsMapper.getTdepartmentsById(id);
    }

    @Override
    public List<Tdepartments> getTdepartmentsListByMap(Map<String, Object> param) {
        return tdepartmentsMapper.getTdepartmentsListByMap(param);
    }

    @Override
    public List<TdepartmentsDto> getTdepartmentsListByMap1(Map<String, Object> param) {
        return tdepartmentsMapper.getTdepartmentsListByMap1(param);
    }

    @Override
    public Integer getTdepartmentsCountByMap(Map<String, Object> param) {
        return tdepartmentsMapper.getTdepartmentsCountByMap(param);
    }

    @Override
    public Integer getTdepartmentsCountByMap1(Map<String, Object> param) {
        return tdepartmentsMapper.getTdepartmentsCountByMap1(param);
    }

    @Override
    public Integer qdtxAddTdepartments(TdepartmentsDto tdepartments) {
        return tdepartmentsMapper.insertTdepartments(tdepartments);
    }

    @Override
    public Integer qdtxModifyTdepartments(TdepartmentsDto tdepartments) {
        return tdepartmentsMapper.updateTdepartments(tdepartments);
    }

    @Override
    public Integer qdtxDeleteTdepartmentsById(Integer id) {
        return tdepartmentsMapper.deleteTdepartmentsById(id);
    }

    @Override
    public Integer qdtxBatchDeleteTdepartments(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return tdepartmentsMapper.batchDeleteTdepartments(param);
    }

    @Override
    public Page<Tdepartments> queryTdepartmentsPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = tdepartmentsMapper.getTdepartmentsCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<Tdepartments> tdepartmentsList = tdepartmentsMapper.getTdepartmentsListByMap(param);
        page.setList(tdepartmentsList);
        return page;
    }

    @Override
    public List<Tdepartments> getTdepartments(Integer hospitalId) {
        return tdepartmentsMapper.getTdepartments(hospitalId);
    }

    @Override
    public List<Integer> getTdepartmentsByCondition(Integer hospitalId, String tdepartmentsName) throws Exception {
        return tdepartmentsMapper.getTdepartmentsByCondition(hospitalId,tdepartmentsName);
    }

    /**
     * 根据医院id和科室id获取科室页面的信息
     * @param hospitalId
     * @param tdepartmentsId
     * @return
     * @throws Exception
     */
    @Override
    public PageDepartmentDto getPageDepartment(Integer hospitalId, Integer tdepartmentsId) throws Exception {
        return tdepartmentsMapper.getPageDepartment(hospitalId, tdepartmentsId);
    }
    public List<Tdepartments> getTdepartments1(Integer departmentsId) {
        return tdepartmentsMapper.getTdepartments1(departmentsId);
    }

    @Override
    public List<Tdepartments> selectTdep(Integer hospitalId, Integer departmentsId) {
        return tdepartmentsMapper.selectTdep(hospitalId,departmentsId);
    }
}